#!/bin/bash

start() {
        ./api_report -config config/config.json > /data/logs/api_report/api_report_console.log 2>&1 &
        sleep 2
        if [[ -n $(ps aux|grep api_report|grep -v grep|grep config|awk '{print $2}') ]];then
          echo "start api_report success"
        fi
}

stop() {
        api_report_pid=$(ps aux|grep api_report|grep -v grep|grep config|awk '{print $2}')
        kill -9 ${api_report_pid}
        echo "stop api_report success"
}

case $1 in
        start)
                start;;
        stop)
                stop;;
        restart)
                stop
                sleep 1
                start;;
        *)
                echo "Usage: ./run.sh start|stop|restart";;
esac
